package com.axing.yuhaigui.config;

import com.volcengine.ark.runtime.service.ArkService;
import okhttp3.ConnectionPool;
import okhttp3.Dispatcher;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

/**
 * Author: 阿星程序员
 * Date: 2025/3/23
 * Function Description:
 *   初始客户端 配置并获取ArkService 对象 ，并可以调用Bean
 *
 */
@Configuration
@ConfigurationProperties(prefix = "ai")
public class AiConfig {
    @Value("${ai.apiKey}")
    private String apiKey;

@Bean
public ArkService arkService() {
    ConnectionPool connectionPool = new ConnectionPool(5, 1, TimeUnit.SECONDS);
    Dispatcher dispatcher = new Dispatcher();
    // The output time of the reasoning model is relatively long. Please increase the timeout period.
    ArkService service = ArkService.builder().timeout(Duration.ofSeconds(1800)).connectTimeout(Duration.ofSeconds(20)).dispatcher(dispatcher).connectionPool(connectionPool).baseUrl("https://ark.cn-beijing.volces.com/api/v3").apiKey(apiKey).build();
    return service;
}

}
